<%-- 
    Document   : add_product
    Created on : 14.04.2013, 14:31:08
    Author     : Yasya, Kate
--%>
<%@page import="facade.CategoryFacadeLocal"%>
<%@page import="javax.naming.NamingException"%>
<%@page import="javax.naming.InitialContext"%>

<%@page import="entity.Category"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%!    private CategoryFacadeLocal categoryFacade;

    public void jspInit() {
        try {
            InitialContext ic = new InitialContext();
            categoryFacade = (CategoryFacadeLocal) ic.lookup(
                    "java:global/Delta/Delta-ejb/CategoryFacade!facade.CategoryFacadeLocal");

        } catch (NamingException ex) {
            ex.printStackTrace();
        }
    }
%>


<!DOCTYPE html>
<html>
    <head>
        <script src="scripts/productValidator.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="css/styl_product.css">
          <link rel="stylesheet" type="text/css" href="css/all.css">
        <title>Add/Edit product</title>
    </head>
    <body>      
        <header>
            <div id ="top_name"> <a href="main.jsp"> <img src="/Delta-war/product/1.jpeg"></a> <h1> Product</h1> </div>
           
        </header>
        <div id="main">
            <div id="label">
                <p>Name:<font color="red">*</font></p>
                <p>Category:</p>
                <p>Price:<font color="red">*</font></p>
                <p>Picture:</p>
                <p>Description:</p>
            </div>
            <div id="add_product" style="position: relative; bottom: 209px; ">  
                <form id="product_form" method="Post" action="AddProduct" enctype="multipart/form-data"> 
                    <p> <input 
                            id="name_input" 
                            type="text" 
                            name="name" 
                            size="50"
                            oninput="validateName()" />
                        <span 
                            style="color: red;" 
                            id="name_error"> 
                            Name should not be empty
                        </span>
                        <span 
                            id="name_length_error" 
                            style="color: red; display:none"> 
                            Name is too long: should be less then 100 characters
                        </span>


                    </p>
                    <p> <select  name="category" size = 1> 

                            <%for (Category c : categoryFacade.findAll()) {%>
                            <option value=<%=c.getId_category()%>> <%= c.getName()%></option>
                            <%}%>


                        </select> </p>
                    <p>   <input
                            id="price_input" 
                            type="text" 
                            name="price" 
                            size="50"
                            oninput="validatePrice()"/>
                        <span 
                            style="color: red;" 
                            id="price_error"> 
                            Price should not be empty
                        </span>
                        <span 
                            id="price_number_error" 
                            style=" color: red; display:none"> 
                            Illegal value: should be numeric and less then 100000 
                        </span>
                    </p>
                     <table>
                        <tr>
                            <td><input type="file" name="file" /></td>
                           
                    </table>
                
                    <p>  <textarea
                            id="description"
                            name="description" 
                            cols="39" 
                            rows="7"
                            oninput="validateDescription()">
                            
                        </textarea>
                    
                    <span 
                            id="description_error" 
                            style="color: red; display:none"> 
                            Description is too long: should be less than 2000 
                        </span>
                    </p>
                    

                </form>
                            <button 
                        id="ok"  
                        onclick="submitForm()" style=" position: relative;   background:  #b8b0fd;left: 1%; ">
                        Ok
                    </button>
                <button id="func" style=" position: relative;   background:  #b8b0fd; left: 5%; bottom: 10px; " onclick="window.location.href='catalog_product.jsp' ">Cancel</button> 
            </div>
        </div>
                            <div id="footer">
                                <p>  &#169;All rights reserved</p>
                            </div>
    </body>
</html>